<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>入库管理</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${Plugins}/dateUtil.js" type="text/javascript"></script>

<style type="text/css">
#searchbar{
   margin-bottom: 10px;
   margin-left:15px;
  }
  .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search {
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
.inputSize {
	width: 150px;
}
select{
	width: 150px;
	font-size: 12px;
}
td{
	font-size: 12px
}
</style>
</head>
<body style="padding:6px; overflow:hidden;">
<div class="navbar">
		<span>您当前的位置：</span>
		出入库管理 &gt; 商品入库管理
</div>

<form action="../../stockmanage/StockController/pageFinderStockIn.do" method="post" >
<div id="searchbar">
<br>
<table  style="width: 80%" border=0> 
	<tr>
		<td  width="10%">	
     		入库单号：
     	</td>
     	<td   width="21%">
     		<input id="stockInNo" name="stockInNo" type="text" value="${stockIn.stockInNo}"  class="inputSize"/>&nbsp;&nbsp;
		</td>
		<td  width="10%">
			入库类型：
		</td>
     	<td> 
			<select   id="stockInType"  name="stockInType">
	            <option value="">请选择</option>
	            <option value="1" <c:if test="${stockIn.stockInType=='1'}">selected="selected"</c:if>>货品采购入库</option>
	            <option value="2" <c:if test="${stockIn.stockInType=='2'}">selected="selected"</c:if>>订单退换货入库</option>
<%-- 	            <option value="3" <c:if test="${stockIn.stockInType=='3'}">selected="selected"</c:if>>次品退换货入库</option>
 --%>	            <option value="4" <c:if test="${stockIn.stockInType=='4'}">selected="selected"</c:if>>采购退换货入库</option>
	            <option value="5" <c:if test="${stockIn.stockInType=='5'}">selected="selected"</c:if>>调拨入库</option>
	            <option value="6" <c:if test="${stockIn.stockInType=='6'}">selected="selected"</c:if>>其他入库</option>
    	  	</select>
 		</td>
 	</tr>
 	<tr style="height: 9px">
     	<td colspan="4"></td>
    </tr>
 	<tr>
 		<td>
 			采购单号：
 		</td>
     	<td> 
 			<input id="purNo" name="purNo" type="text" value="${stockIn.purNo}" class="inputSize"/>&nbsp;&nbsp;
 		</td>
	 	<td>
	 		仓库：
	 	</td>
     	<td>
	 		<select id="whNo"  name="whNo">
	            <option value="">请选择</option>
	            <c:forEach var="temp" items="${whareHouse}">
	            	<option value="${temp.whNo}" <c:if test="${stockIn.whNo==temp.whNo}">selected="selected"</c:if>>${temp.whName}</option>
	            </c:forEach>
	        </select>
   		</td>
	<tr style="height: 9px">
     	<td colspan="4"></td>
   </tr>
   <tr>
   		<td>
   			创建时间：
   		</td>
     	<td>
   			<input style="width: 150px" id="beginTime" type="text" name="beginTime" readonly="readonly" value="${stockIn.beginTime}" class="Wdate" value="" size="21"
	    		onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,maxDate:'#F{$dp.$D(\'endTime\')||\'2020-10-01\'}'})" >
		</td>
		<td>
			至
		</td>
     	<td>
    		<input style="width: 150px" id="endTime" type="text" name="endTime" readonly="readonly" value="${stockIn.endTime}" class="Wdate" value="" size="21"
    			onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'#F{$dp.$D(\'beginTime\')||\'2013-01-01\'}'})" >
		   <input id="btnOK" type="submit" value="查询" class="l-button-search" />
           <input type="button" id="resetBtn" value="重置" class="l-button-search" />
		</td>
	</tr>
</table>
</div>
</form>

<div id="maingrid4" style="margin:0; padding:0"></div>
  <div style="display:none;">
  <!-- g data total ttt -->
</div>

<script>
	var tabId = window.top.tab.getSelectedTabItemID();
    var basePath='${BasePath}';
    var grid = null;
    $(function () {
    	 // 重置
        $("#resetBtn").click(function(){
    		$('#searchbar :input').not(':submit, :button, :reset').val('').removeAttr('checked').removeAttr('selected');
    	});    	
        grid = $("#maingrid4").ligerGrid({
            columns: [
            { display: '入库单号', name: 'stockInNo',width:120},
            { display: '入库类型', name: 'stockInType' ,render:function(rowdata,rowindex,value){
                var text = null;
                switch(value){
	                case 1: text="货品采购入库"; break;
	                case 2: text="订单退换货入库"; break; 
	                case 3: text="次品退换货入库"; break;
	                case 4: text="采购退换货入库"; break;
	                case 5: text="调拨入库 "; break; 
	                case 6: text="其他入库"; break;
	                default : break; 
                }
                return text; 
            }},
            { display: '仓库', name: 'whName'},
            { display: '供应商名称', name: 'supName'},
            { display: '采购单号', name: 'purNo',width:120,render:function(rowdata,rowindex,value){
            	if(value == null || value == 'null'){
            		return '';
            	}
            	return value;
            }},
            { display: '创建时间', name: 'createTime'},
            { display: '入库时间', name: 'updateTime'},
            { display: '入库人员', name: 'updater'},
            { display: '入库状态', name: 'stockInState' ,render:function(rowdata,rowindex,value){
	            var text = null;
		            switch(value){
		            case 1: text="已入库"; break;
		            case 0: text="未入库"; break;       
		            default : break; 
	            }
	            return text;
            }},
            { display: '操作',name: 'stockInState', isSort: false, render: function (rowdata, rowindex, value){
            	if(value == 0){
            		return "<a id = 'operate1' href='javascript:toStockInApprove(" + rowindex + ")'>入库</a>&nbsp;&nbsp;";
            	}else{
            		return "<a id = 'operate2' href='javascript:toStockInDetail(" + rowindex + ")'>详情</a>&nbsp;&nbsp;";
            	}
            }}
            ], 
            pageSize:30,
            width: '100%',
            height: '100%',
            dataType: 'server',
            dataAction: 'server',
            pagesizeParmName: 'pageSize',
            parms: [
					{name: "stockInNo", value:$("#stockInNo").val()},
					{name: "stockInType", value:$("#stockInType").val()},
					{name: "whNo", value:$("#whNo").val()},
					{name: "purNo", value:$("#purNo").val()},
					{name: "beginTime", value:getFullTime($("#beginTime").val(),true)},
					{name: "endTime", value:getFullTime($("#endTime").val(),false)}
                    ],
             url: "ajaxPageFinderStockIn.do",
             toolbar: {items: [{ text: "导出EXCEL", click: exportExcel, icon: "up" },{line: true}]}		
        });
    });
   
  function toStockInApprove(rowindex){
	  	var stockInNo=grid.getData()[rowindex].stockInNo;	
		var url= basePath + '/stockmanage/StockController/toStockInApprove.do?tabId='+tabId+'&stockInNo='+stockInNo;
		window.parent.f_addTab('入库','入库',url);
  } 
  function toStockInDetail(rowindex){
	  	var stockInNo=grid.getData()[rowindex].stockInNo;	 
		var url= basePath + '/stockmanage/StockController/toStockInDetail.do?tabId='+tabId+'&stockInNo='+stockInNo;
		window.parent.f_addTab('详情','详情',url);
  } 
  
  function approveStockIn(rowindex){
	  $.ajax({
          async: false,
          type: 'post',
          dataType: 'text',
          data: {id:grid.getData()[rowindex].id},
          url: basePath+"/stockmanage/StockController/approveStockIn.do",
          success: function (data) {
        	  if(data == 'fail'){
        		  window.parent.f_tip('入库失败');
        	  }else{
        		  window.parent.f_tip('入库成功');
	        	  $('#operate1').hide();
        	  }
          }
      });
  }
  
  function openAddWindow(){
	var url = '${BasePath}/stockmanage/StockController/toAddStockIn.do';
  	window.parent.f_addTab('新增','新增',url);
 	//var m=$.ligerDialog.open({title:'新增入库信息',url:'${BasePath}/stockmanage/StockController/addStockIn.do',height:550,width:1024,isResize: false, isDrag: false });
  	//m.show(); 
 }
  
 function exportExcel(){
	var exportUrl = '${BasePath}/stockmanage/StockController/exportStockIn.do';
	var params = [{name: "stockInNo", value:$("#stockInNo").val()},
				{name: "stockInType", value:$("#stockInType").val()},
				{name: "whNo", value:$("#whNo").val()},
				{name: "purNo", value:$("#purNo").val()},
				{name: "beginTime", value:getFullTime($("#beginTime").val(),true)},
				{name: "endTime", value:getFullTime($("#endTime").val(),false)}];
     var form = $("<form>");   //定义一个form表单
     form.attr('style', 'display:none');   //在form表单中添加查询参数
     form.attr('target', '');
     form.attr('method', 'post');
     form.attr('action', exportUrl);
     for(var i=0;i<params.length;i++){
     	var input = $('<input>');
         input.attr('type', 'hidden');
         input.attr('name', params[i].name);
         input.attr('value', params[i].value);
         form.append(input);   //将查询参数控件提交到表单上
     }
     $('body').append(form);  //将表单放置在web中 
     form.submit();
     form.remove();
 }
 
   
</script>
</body>
</html>